package com.zdb.demo.design.principle.dependenceinversion;

public class Student {

//    v1
//    public void studyCourse(ICourse iCourse) {
//        iCourse.studyCourse();
//    }
//
//    public static void main(String[] args) {
//        Student student = new Student();
//        student.studyCourse(new JavaCourse());
//        student.studyCourse(new PythonCourse());
//    }

    private ICourse iCourse;

//    v2
//    public Student(ICourse iCourse) {
//        this.iCourse = iCourse;
//    }
//
//    public void studyCourse() {
//        iCourse.studyCourse();
//    }
//
//    public static void main(String[] args) {
//        Student student = new Student(new JavaCourse());
//        student.studyCourse();
//    }

    public void studyCourse() {
        iCourse.studyCourse();
    }

    public static void main(String[] args) {
        Student student = new Student();
        student.setiCourse(new JavaCourse());
        student.studyCourse();

        student.setiCourse(new PythonCourse());
        student.studyCourse();
    }

    public void setiCourse(ICourse iCourse) {
        this.iCourse = iCourse;
    }
}
